#include <bits/stdc++.h>
using namespace std;

typedef map<int,int>::iterator Mite ;

map<int, int> ans;

int main() {
    int N, t, a;
    cin >> N;  t = N;
    while(t--) {
        cin >> a;
        ans[a] += 1;
    }
    int max_val = INT_MIN, max_time =  INT_MIN;
    for(Mite ite = ans.begin(); ite != ans.end(); ++ite ) {
        if(ite->second > max_time) max_time = ite->second, max_val = ite->first;
        else if(ite->second == max_time && ite->first < max_val)   max_time = ite->second, max_val = ite->first;
    }
    cout << max_val << endl;
    return 0;
}